﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Net.Formats.oEmbed
{
    [TestClass]
    public class LinkResponseTests
    {
        [TestMethod]
        public void CreateLinkResponsePositiveTest( )
        {
            var response = new LinkResponse( );
            response.AuthorName = "John Doe";
            response.CacheAge = null;
            response.ProviderName = "Test provider";            
            response.Version = "1.0";

            Assert.IsNotNull( response );
            Assert.IsInstanceOfType( response, typeof( GenericResponse ) );
            Assert.IsInstanceOfType( response, typeof( LinkResponse ) );
            Assert.AreEqual( response.Type, ResponseType.Link );
            Assert.AreEqual( "1.0", response.Version );
            Assert.AreEqual( "John Doe", response.AuthorName );
            Assert.AreNotEqual( "test Provider", response.ProviderName ); 
        }

        [TestMethod]
        [ExpectedException(typeof(NotSupportedException))]
        public void CreateLinkResponseNegativeTest( )
        {
            var response = new LinkResponse( );
            response.Version = "2.0";
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void ThumbnailPropertiesValidationTest( )
        {
            var linkResponse = new LinkResponse( );
            linkResponse.ThumbnailUrl = new Uri( "http://www.google.com/test?width=40&height=50" );

            Assert.IsNotNull( linkResponse.ThumbnailUrl );
        }

        [TestMethod]
        public void ThumbnailPropertiesNotSetTest( )
        {
            var linkResponse = new LinkResponse( );
            linkResponse.Version = "1.0";
            linkResponse.AuthorName = "John Doe";

            Assert.IsNull( linkResponse.ThumbnailUrl );
            Assert.IsNull( linkResponse.ThumbnailHeight );
            Assert.IsNull( linkResponse.ThumbnailWidth );
        }

        [TestMethod]
        public void ThumbnailPropertiesAllSetTest( )
        {
            var linkResponse = new LinkResponse( );
            linkResponse.Version = "1.0";
            linkResponse.AuthorName = "John Doe";
            linkResponse.ThumbnailWidth = 20;
            linkResponse.ThumbnailHeight = 34;
            linkResponse.ThumbnailUrl = new Uri( "http://someurl.com/oembed" );

            Assert.IsNotNull( linkResponse.ThumbnailUrl );
            Assert.AreEqual( "http://someurl.com/oembed", linkResponse.ThumbnailUrl.AbsoluteUri );
            Assert.AreEqual( 20, linkResponse.ThumbnailWidth.Value );
            Assert.AreEqual( 34, linkResponse.ThumbnailHeight.Value );
        }
    }
}
